#include "WLog.h"

using namespace std;

WLog::LogLevel WLog::s_currentLogLevel = WLog::INFO;

WLog::WLog()
{

}


WLog::~WLog()
{
    log(_level, _logStream.str());
}

void WLog::setLogLevel(LogLevel level)
{
    s_currentLogLevel = level;
}

WLog::LogLevel WLog::getLogLevel()
{
    return s_currentLogLevel;
}

string WLog::logLevelToString(LogLevel level)
{
    switch (level)
    {
        case ERROR: return "ERROR";
        case WARNING: return "WARNING";
        case INFO: return "INFO";
        case DEBUG: return "DEBUG";
        default: return "UNKNOWN";
    }
}

void WLog::log(LogLevel level, const string &message)
{
    if (level > s_currentLogLevel)
    {
        return;
    }

    switch (level)
    {
        case ERROR:
        {
            Loge("%s", message.c_str());
            break;
        }
        case WARNING:
        {
            Logw("%s", message.c_str());
            break;
        }
        case INFO:
        {
            Logi("%s", message.c_str());
            break;
        }
        case DEBUG:
        {
            Logi("%s", message.c_str());
            break;
        }
        default:
        {
            Loge("unkown log level");
        }
    }


}
